home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / bin / tackdown / origin.common.c < prev    next >
C/C++ Source or Header  |  1992-12-09  |  3KB  |  138 lines

  1. #include <stdio.h>
  2. #include "geom.h"
  3. #include "streampool.h"
  4. #include "origin.common.h"
  5.  
  6. static char targetname[255];
  7.  
  8. static int neutral;
  9.  
  10. static Pool *infile;
  11.  
  12. /* Return ui to state where there are no axes visible */
  13. static void NeutralState() {
  14.   neutral = 1;
  15.   uiDisableDoneCancel();
  16.   uiEnableShow();
  17.   uiSetInstructions("Click on the \"Show Origin\"",
  18.             "button to display the",
  19.             "coordinate axes of the",
  20.             "named object.");
  21.             
  22. }
  23.  
  24. /* Set ui to state where there are axes visible */
  25. static void NonNeutralState() {
  26.   neutral = 0;
  27.   uiEnableDoneCancel();
  28.   uiDisableShow();
  29.   uiSetInstructions("Now move the axis around in",
  30.             "Geomview to move the origin of",
  31.             "the named object.  Then",
  32.             "click the \"Done\" button.");
  33.            
  34. }
  35.  
  36. void internalsInit() {
  37.   uiSetTargetname("targetgeom");
  38.  
  39.   infile = PoolStreamTemp(NULL, stdin, 0, NULL); 
  40.  
  41.   NeutralState();
  42. }
  43.  
  44. void internalsShow() 
  45. {
  46.   Transform T;
  47.  
  48.   uiGetTargetname(targetname);
  49.  
  50.   printf("(echo \"{ \")");
  51.   printf("(write transform - %s world)", targetname);
  52.   printf("(echo } )");
  53.   fflush(stdout);
  54.   if (!TransStreamIn(infile, NULL, T)) {
  55.     uiError("Unable to find transform of", "named item.  Perhaps",
  56.         "the object does not exist.");
  57.     return;
  58.   }
  59.  
  60.   printf("(progn ");
  61.   printf("(geometry axes.%s < axes.list) ", targetname);
  62.   printf("(normalization axes.%s none) ", targetname);
  63.   printf("(xform-set axes.%s", targetname);
  64.   fputtransform(stdout, 1, &T[0][0], 0);
  65.   printf(") ");
  66.   printf(")");
  67.   fflush(stdout);
  68.   NonNeutralState();
  69. }
  70.  
  71. static void DeleteAxes() {
  72.   printf("(delete axes.%s)", targetname);
  73.   fflush(stdout);
  74. }
  75.  
  76. void internalsDone() {
  77.   Geom *g;
  78.   Transform w2axes, w2target, axes2w, axes2target;
  79.  
  80.   printf("(echo \"{ \")");
  81.   printf("(write transform - axes.%s world)", targetname);
  82.   printf("(echo } )");
  83.   fflush(stdout);
  84.   if (!TransStreamIn(infile, NULL, w2axes)) {
  85.     uiError("Unable to find axes.  Perhaps", "they were deleted in",
  86.         "Geomview.");
  87.     NeutralState();
  88.     return;
  89.   }
  90.  
  91.   printf("(echo \"{ \")");
  92.   printf("(write geometry - %s bare)", targetname);
  93.   printf("(echo } )");
  94.   fflush(stdout);
  95.   g = GeomFLoad(stdin, NULL);
  96.   if (g == NULL) 
  97.     uiError("Unable to find", "target object.  Perhaps", 
  98.         "it has been deleted.");
  99.   else {
  100.     printf("(echo \"{ \")");
  101.     printf("(write transform - %s world)", targetname);
  102.     printf("(echo } )");
  103.     fflush(stdout);
  104.     if (!TransStreamIn(infile, NULL, w2target)) {
  105.       uiError("Unable to find transform of", "named item.  Perhaps",
  106.           "the object does not exist.");
  107.       return;
  108.     }
  109.     TmInvert(w2axes, axes2w);
  110.     TmConcat(axes2w, w2target, axes2target);
  111.     GeomTransform(g, axes2target);
  112.  
  113.     printf("(progn ");
  114.     printf("(geometry %s ", targetname);
  115.     GeomFSave(g, stdout, NULL);
  116.     printf(")");
  117.     printf("(xform-set %s ", targetname);
  118.     fputtransform(stdout, 1, &w2axes[0][0], 0);
  119.     printf(")");
  120.     printf(")");
  121.     fflush(stdout);
  122.   }
  123.  
  124.   DeleteAxes();
  125.   NeutralState();
  126. }
  127.  
  128. void internalsCancel() {
  129.   DeleteAxes();
  130.   NeutralState();
  131. }
  132.  
  133. void internalsQuit() {
  134.   PoolDelete(infile);
  135.   exit(0);
  136. }
  137.   
  138.